home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
cpphtp2
/
code.jar
/
code
/
ch03
/
fig03_14.txt
< prev
next >
Wrap
Text File
|
1998-02-27
|
632b
|
24 lines
1 // Fig. 3.14: fig03_14.cpp
2 // Recursive factorial function
3 #include <iostream.h>
4 #include <iomanip.h>
5
6 unsigned long factorial( unsigned long );
7
8 int main()
9 {
10 for ( int i = 0; i <= 10; i++ )
11 cout << setw( 2 ) << i << "! = " << factorial( i ) << endl;
12
13 return 0;
14 }
15
16 // Recursive definition of function factorial
17 unsigned long factorial( unsigned long number )
18 {
19 if ( number <= 1 ) // base case
20 return 1;
21 else // recursive case
22 return number * factorial( number - 1 );
23 }